package com.skynet.supervision.aop.uac;

import cn.hutool.core.bean.BeanUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * acl 权限校验
 *
 * @author xuchao
 * @date 2023-03-08 20:27
 */
@SuppressWarnings("unused")
@Aspect
@Slf4j
public class ACLAspect {

    @Resource
    private UACClientProperties properties;


    @Pointcut("@annotation(com.skynet.supervision.aop.uac.ACL)")
    private void cutMethod() {
        // Do nothing because of @Pointcut must be empty body.
    }

    @Around("cutMethod()")
    @SneakyThrows
    public Object around(ProceedingJoinPoint joinPoint) {
        boolean enableAcl = !BeanUtil.isEmpty(this.properties)
                && Optional.ofNullable(this.properties.getEnable()).orElse(false)
                && Optional.ofNullable(this.properties.getEnableAcl()).orElse(false);
        if (enableAcl) {
            //TODO impl the acl function
        }
        return joinPoint.proceed();
    }
}
